﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2_Strategy
{
    /*
     工厂和策略模式结合
         */
    public class OperationContext
    {
        private BaseOperation context;

        /*
         选择类型，传递参数
         TODO ： 改进 进行 反射
             */

        public void SwitchOperation(string operationType)
        {
            switch (operationType)
            {
                case "+":
                    context = new AddOperation();
                    break;
                case "-":
                    context = new SubOperation();
                    break;
                case "*":
                    context = new MultiOperation();
                    break;
                case "/":
                    context = new DivisionOperation();
                    break;
                default:
                    context = new NoneOperation();
                    break;
            }
        }

        public float GetResult(float firstParam,float secondParam)
        {
            context.FirstParams = firstParam;
            context.SecondParams = secondParam;
            return  context.Operation();
        }
    }
}
